


cowboybot.py

by JoCarthage



Category: Roswell New Mexico (TV 2019)
Genre: a different use for the archive, not fanfiction, python bot
Language: English
Status: Completed
Published: 2020-09-21
Updated: 2020-09-21
Packaged: 2021-03-07 23:49:05
Rating: General Audiences
Warnings: No Archive Warnings Apply
Chapters: 1
Words: 762
Publisher: archiveofourown.org
Story URL: https://archiveofourown.org/works/26576320
Author URL: https://archiveofourown.org/users/JoCarthage/pseuds/JoCarthage
Summary: We were chatting on the Roswell 18+ Discord server about Michael Guerin writing himself a therapy bot. I've done that 3-4 times this year and decided tonight's coding project would be writing a therapy bot from Michael's perspective. Unless you're comfortable working in an IDE, you probably won't be able to play with this, so this is very, very niche posting.It's pretty rare for me to use this Ao3 account for archiving anything other than fic, and I promise it won't be a regular habit (I know I'd be bummed if I got a notification from an author I subscribed to and then found a bunch of code rather than some lovely fic); but I thought this was a fun, fannish artifact I wanted to keep here.If you're interested in the meta process behind this chatbot, I've put my thinking in the author's note.Download the source code here and the relevant questions here: https://drive.google.com/drive/folders/1BVBdvojT8k_hKWy7MnjJ34VL-WcS2Ykp?usp=sharing
Comments: 2
Kudos: 11





	cowboybot.py

**Author's Note:**

> So, in building this chatbot, I wanted to think about what kinds of questions Michael needs to ask himself, as well as what kinds of protections he'd want and need from a therapist. The first question the chatbot asks is for a safeword. The entire process stops immediately if Michael types in his safeword, no nudging, no pushing, no nothing.
> 
> Then there's the actual questions. I put together 2 files of questions: fairly standard talk-therapy questions and then mindfulness questions. Mindfulness shows up in CBT and DBT treatment, as well as other treatments that Michael might have researched, and they're fairly innocuous questions, though if you've never had awareness of pain or tension in your body, they can be upsetting and startling (thus, the safe word). He lets the computer's internal clock choose for him whether he gets a mindfulness question or a therapy question. And every 5 minutes, he gets a math break, so he can answer a simple math question.
> 
> This chatbot keeps a record of his responses, but doesn't use them and as soon as he safewords out, it deletes them (well, technically, the Python IDE's garbage collector function deletes them). He could (and I have) write a version of this that goes through his responses, asks him questions about why he said what he said. But this is a simple chatbot. This chatbot also checks if he's cussing out his chatbot therapist, but doesn't take any action based off of that; he could (and I have) written chatbots that respond differently to hostile responses, just like a living therapist would.
> 
> I chose Python 3 for this project because I think it's easier to read, it's certainly faster to code in, and it's a lot lighter weight than something like Java, which might be hard to run on a third-hand machine. It's also an evolution of Python 3, which is a scripting language and I could see Michael and Alex being script kiddies together in 2008.
    
    
    #the purpose of this is to write a chatbot for therapy, from Michael Guerin's perspective  
    import random  
    import time  
      
    class cowboybot:  
      
        math_request = "i need math"  
      
        def __init__(self, mindfulness_qs, math_questions, therapist_qs):  
            self._mindfulness_qs = mindfulness_qs  
            self._math_qs = math_questions  
            self._therapist_qs = therapist_qs  
      
        @property  
        def mindfulness_qs(self):  
            return self._mindfulness_qs  
      
        @mindfulness_qs.setter  
        def mindfulness_qs(self, poem):  
            if type(poem) is not list:  
                raise ValueError("the inputted value for poem isn't a list and it must be")  
            self._mindfulness_qs = poem  
      
        @property  
        def math_questions(self):  
            return self._math_qs  
      
        @math_questions.setter  
        def math_questions(self, math_questions):  
            if type(math_questions) is not list:  
                raise ValueError("the inputted value for for a list isn't a list and it must be")  
            self._math_qs = math_qs  
      
        @property  
        def therapist_qs(self):  
            return self._therapist_qs  
      
        @therapist_qs.setter  
        def therapist_qs(self, therapist_qs):  
            if type(therapist_qs) is not list:  
                raise ValueError("the inputted value for for a list isn't a list and it must be")  
            self._therapist_qs = therapist_qs  
      
        def rand_mindfulness_line(self):  
            return random.choice(self.mindfulness_qs)  
      
        def rand_math_line(self):  
            return random.choice(self.math_questions)  
      
        def rand_therapist_line(self):  
            return random.choice(self.therapist_qs)  
      
        def chat_nicer(self):  
            safe_word = input("before we begin, what is your safeword?\n")  
            chit_cat = input("I'll remember that. And I'll stop immediately if you say it.\n")  
            chit_cat = input("about every 5 minutes, we'll have a math break, just hit enter when a math question comes up if you don't need a break at that moment \n")  
            therapist_reply = ""  
            mindfulness_reply = ""  
            their_replies = []  
            warning_words = ["fuck", "shit", "bitch",  "shut up", "cunt"]  
            bad_language_reply = ""  
            now = time.time()  
      
            while therapist_reply.lower() != safe_word and mindfulness_reply.lower() != safe_word:  
                oldtime = time.time()  
                pseudo_rand_number = int(oldtime) % 2  
                if pseudo_rand_number == 0:  
                    their_reply = input(self.rand_therapist_line() + "\n")  
                else:  
                    their_reply = input(self.rand_mindfulness_line() + "\n")  
                if time.time() - oldtime > 300:  
                    math_reply = input(self.rand_math_line())  
      
                their_replies.append(their_reply)  
                for w in warning_words:  
                    if w in mindfulness_reply or w in therapist_reply:  
                        bad_language_reply = input(self.rand_therapist_line() + "\n")  
                        their_replies.append(bad_language_reply)  
            return  
      
    mindfulness_qs = 'mindfulness_qs.txt'  
    math_qs = 'math_qs.txt'  
    therapist_qs = 'therapist_qs.txt'  
    mindfulness_line_list = [line.rstrip('\n') for line in open(mindfulness_qs)]  
    math_line_list = [line.rstrip('\n') for line in open(math_qs)]  
    therapist_qs_line_list = [line.rstrip('\n') for line in open(therapist_qs)]  
      
    m = cowboybot(mindfulness_line_list, math_line_list, therapist_qs_line_list)  
    m.chat_nicer()
    
    
      
      
    """  
    Contents of therapist_qs.txt
    
    
    What brings you here?  
    
    What is the problem from your viewpoint?  
    
    How does this problem typically make you feel?  
    
    What makes the problem better?  
    
    If you could wave a magic wand, what positive changes would you make happen in your life?  
    
    Overall, how would you describe your mood?  
    
    Tell me more  
    
    I'd love to know more about that  
    
    how does that make you feel?  
    
    Tell me more  
    
    Tell me more  
    
    Tell me more  
    
    Tell me more  
    
    Tell me more  
    
    Tell me more  
    
    Tell me more  
    
    Tell me more  
    
    Tell me more  
    
    Tell me more  
    
    Tell me more  
    
    Tell me more  
    
    Tell me more  
    
    Tell me more  
    
    Tell me more  
    
    Tell me more  
    
    Tell me more  
    
    Tell me more  
    
      
    
    Contents of mindfulness_qs.txt
    
    
    can you take a moment to think about where you're holding tension in your body?  
    
    are you in physical pain right now?  
    
    is your jaw tense?  
    
    are your shoulders tense?  
    
    is your stomach hurting right now?  
    
    are your hips tense?  
    
    is one of your hands hurting right now?  
    
    can you take a long breath in (8 seconds), hold for a bit (4 seconds), then let it out for a bit (4 seconds)?  
    
    can you take 5 slow, even breaths?  
    
    can you take a breath in slowly through your nose, out through your mouth? Can you do it again?  
    
    can you do a body scan right now?  
    
    can you do a progressive relaxation exercise right now?  
    
      
    
    Contents of math_qs.txt
    
    
    Write 230,000,000,000 in scientific notation.  
    
    30 - 12÷3×2 =  
    
    |4 - 8(3 - 12)| - |5 - 11| =  
    
    -18 + 4(6 ÷ 2)2  
    
    11 + sqrt(-4 + 6×4÷3)  
    
    12x3 - 3(2x3 + 4x -1) - 5x + 7  
    
    (x4 / x3)3  
    
    (3x2y-2)3 / (9xy3)3  
    
    (2x-3y4)3(x3 + y)0 / (4xy-2)3  
    
    Write as a mathematical inequality:"9 is less than the product of M and N".  
    
    Find the slope of the line perpendicular to the line y = (1/3)x - 7  
    
    Write an equation of the line with slope -3 and y-intercept (0 , -5).  
    
    -5x + 20 = 25  
    
    Solve the inequality: -3x + 4 < -8  
    
    2x2 - 32 = 0  
    
    -0.25 x + 1.3 = -0.55 x - 0.2  
    
    -0.25 x2 + 1.5 = -10.75  
    
    What is the slope of a line perpendicular to the line x = -3?  
    
    What is the slope of a line parallel to the line x = 5?  
    
    What is the slope of a line perpendicular to the line y = 6?
    
    
      
    
    """


End file.
